#include <bits/stdc++.h>
#define debug cerr << "\33[33m[" << __LINE__ << "]\33[m "
#define SZ(x) ((int) x.size() - 1)
#define all(x) x.begin(), x.end()
#define ms(x, y) memset(x, y, sizeof x)
#define F(i, x, y) for (int i = (x); i <= (y); ++i)
#define DF(i, x, y) for (int i = (x); i >= (y); --i)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
template <typename T> T& chkmax(T& x, T y) { return x = max(x, y); }
template <typename T> T& chkmin(T& x, T y) { return x = min(x, y); }
template <typename T> T& read(T& x) {
    x = 0; int f = 1; char c = getchar();
    for (; !isdigit(c); c = getchar()) if (c == '-') f = - 1;
    for (; isdigit(c); c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48);
    return x *= f;
}
const int N = 1e5 + 10, T = 1e6, M = 1e6 + 10, inf = 1e9;
int n, m, L, V, d[N], v[N], a[N], s[M], p[N], lim[N], ans, mx, tl[M], tr[M];
// int f[N];
void ins(int l, int r) {
    // assert(l <= r);
    if (s[r] - (!l ? 0 : s[l - 1])) {
        // debug << l << " " << r << " " << lower_bound(p + 1, p + m + 1, l) - p << " " << upper_bound(p + 1, p + m + 1, r) - p - 1 << endl;
        l = tr[l], r = tl[r];
        assert(l <= r);
        ans++;
        chkmax(lim[r + 1], l);
        chkmax(mx, l);
    }
}
void zhk() {
    mx = - 1;
    ans = 0;
    read(n), read(m), read(L), read(V);
    F(i, 1, n) {
        read(d[i]), read(v[i]), read(a[i]);
    }
    F(i, 0, T) {
        tl[i] = tr[i] = - 1;
        s[i] = 0;
    }
    F(i, 1, m) {
        lim[i] = - 1;
    }
    F(i, 1, m) {
        s[read(p[i])]++;
        tl[p[i]] = tr[p[i]] = i;
    }
    DF(i, T - 1, 0)
        if (tr[i] == - 1) tr[i] = tr[i + 1];
    F(i, 1, T)
        if (tl[i] == - 1) tl[i] = tl[i - 1];
    F(i, 1, T) {
        s[i] += s[i - 1];
    }
    F(i, 1, n) {
        if (a[i] > 0) {
            if (v[i] > V) {
                ins(d[i], L);
            } else {
                int w = V * V - v[i] * v[i];
                w = w / (2 * a[i]) + 1;
                w += d[i];
                if (w <= L) {
                    ins(w, L);
                }
            }
        } else if (a[i] == 0) {
            if (v[i] > V) {
                ins(d[i], L);
            }
        } else {
            if (v[i] > V) {
                int w = v[i] * v[i] - V * V;
                w = (w - 1) / (2 * (- a[i]));
                // assert(w >= 0);
                w += d[i];
                ins(d[i], min(w, L));
            }
        }
    }
    int s = 0;
    F(i, 2, m) chkmax(lim[i], lim[i - 1]);
    for (int i = mx; i != - 1; i = lim[i]) {
        // debug << i << " " << lim[i] << endl;
        s++;
    }
    cout << ans << ' ' << m - s << '\n';
    // exit(0);
    // F(i, 0, mx) {
    //     if (lim[i] == - 1) f[i] = 1;
    //     else f[i] = f[lim[i]]
    // }
}
signed main() {
    freopen("detect.in", "r", stdin);
    freopen("detect.out", "w", stdout);
    int _; read(_);
    while (_--) zhk();
    return 0;
}